<template>
    <div class="order_item">
        <div v-if="i.status == 3">
            <label class="remember_content"><input type="checkbox" v-model="checked" name="rememberPwd" class="remember_pwd" @change="onOrderChange(i.order_no)">勾选结算</label>
        </div>
        <div class="address-info">
            <div class="order-address"><p class="address-text">{{i.dormitory_name}}-{{i.floor_name}}-{{i.address}}</p><span class="code">{{i.code}}</span></div>
            <mt-cell :title="i.consignee_name+'/'+i.consignee_phone">{{timestampToTime(i.create_time)}}</mt-cell>
        </div>
        <div class="address-info">
            <p class="order-address">{{i.shop_name}}</p>
            <mt-cell :title="i.address"></mt-cell>
        </div>
        <div class="address-info goods-order">
            <div>
                <p class="order-goods">{{i.order_detail[0].goods.name}}等{{i.order_detail.length}}件商品</p>
                <p class="order-no" id="order-code" :data-clipboard-text="i.order_no"><span>{{i.order_no}}</span><i> | </i><span @click="copy(i.order_no)">复制</span></p>
            </div>
            <router-link :to="{path:'/orderInfo',query:{order_no:i.order_no}}"><i class="iconfont icon-gengduo"></i></router-link>
            <!-- <mt-cell :title="i.consignee_name+'/'+i.consignee_phone">{{timestampToTime(i.create_time)}}</mt-cell> -->
        </div>
        <!-- <mt-cell v-for="(a,index) of i.order_detail" :key="index" :title="'商品'+':'+ a.goods.name+'X'+a.goods_num">￥{{a.goods_price}}</mt-cell> -->
        <p v-for="(a,index) of i.order_detail" :key="index" class="order-good"><span>{{a.goods.name}}</span><span>×{{a.goods_num}}</span><span>{{a.goods_price}}</span></p>
        <!-- <mt-cell title="商家店铺:">{{i.shop_name}}</mt-cell>
        <mt-cell title="商家地址:">{{i.address}}</mt-cell>
        <mt-cell title="下单用户姓名:">{{i.consignee_name}}</mt-cell>
        <mt-cell class="order_detail order_user" title="下单用户电话:">{{i.consignee_phone}}</mt-cell>
        <mt-cell title="下单用户地址:">{{i.school_name}}-{{i.dormitory_name}}-{{i.consignee_address}}</mt-cell> -->
        <mt-cell title="下单用户备注:"></mt-cell>
        <p class="remark">{{!i.remark?"无备注":i.remark}}</p>
        <p class="order_detail">合计:{{i.total_price}}</p>
        <p class="order_detail earn">预计收入:<span>￥{{i.floor_price}}元</span></p>
        <div class="btn_group">
            <a :href="'tel:'+i.bank_phone">
                <mt-button class="btn" >联系商家</mt-button>
            </a>
            <a :href="'tel:'+i.phone">
                <mt-button class="btn" >联系用户</mt-button>
            </a>
            <mt-button class="btn btn-1" @click="RiderRob(i.order_no)" v-if="i.status == 1">接单</mt-button>
            <mt-button class="btn" @click="RiderDelivery(i.order_no)" v-if="i.status == 2">收到商品</mt-button>
            <mt-button class="btn" @click="RiderArrive(i.order_no)" v-if="i.status == 3 && i.is_arrive">确认送达</mt-button>
        </div>
    </div>
</template>
<script>
import {riderRob,riderDelivery,riderArrive} from '../api'
import {Toast} from 'mint-ui'
export default {
    name:"storeOrderList",
    props:["i"],
    data() {
        return {
            checked:false
        }
    },
    methods:{
        RiderRob(order_no){
            const data = {
                token:this.$store.getters.token,
                order_no,
                user_id:this.$store.getters.userInfo.id
            };
            riderRob(data).then(res=>{
                console.log(res);
                Toast(res.msg)
                if(res.code==200){
                    // this.$router.go(0);
                    this.$emit("onUpdate")
                }
            })
        },
        RiderDelivery(order_no){
            const data = {
                token:this.$store.getters.token,
                order_no
            }
            riderDelivery(data).then(res=>{
                console.log(res);
                Toast(res.msg)
                if(res.code==200){
                    this.$emit("onUpdate")
                    // this.$router.go(0);
                }
            })
        },
        RiderArrive(order_no){
            const data = {
                token:this.$store.getters.token,
                order_no,
                user_id:this.$store.getters.userInfo.id
            }
            riderArrive(data).then(res=>{
                console.log(res);
                Toast(res.msg)
                if(res.code==200){
                    // this.$router.go(0);
                    this.$emit("onUpdate","onUpdate")
                }
            })
        },
        copy(){
            new Clipboard("#order-code").on('success',()=>{
                Toast('复制订单号码成功');
            })
        },
        onOrderChange(order_no){
                this.$emit('onOrderChange',order_no,this.checked);
        }
    }
}
</script>
<style scoped>
    .order_item{
        border-bottom: 1px solid #ccc;
        padding:0 1rem;
        margin: 1rem 0;
        background: #fff;
    }
    .order_item::before{
        content: "";
        display: table;
    }
    .order_detail{
        text-align: right;
        margin-right: 0.6rem;
        line-height: 1.4rem;
        font-size: 1.2rem;
        font-weight: bolder;
    }
    .remark{
        word-wrap: break-word;
        width: 80%;
        margin: auto;
    }
    .code{
        color: #F23D3D;
        position: absolute;
        right: 1.2rem;
        line-height: 2rem;
    }
    .address-info{
        padding-top: 0.5rem;
    }
    .goods-order{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid #D8D8D8;
    }
    .goods-order .iconfont{
        color: #F0463C;
        font-size: 1.2rem;
    }
    .order-address{
        font-size: 1.2rem;
        font-weight: bolder;
        padding: 0 0.3rem;
        display: flex;
    }
    .order-address .address-text{
        width: 80%;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        word-break: break-all;
    }
    .order-goods{
        font-size: 1rem;
        font-weight: bolder;
    }
    .order-good{
        width: 80%;
        margin: 1rem 0;
        margin-left: 20%;
        line-height: 2rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .order-good span{
        width: 33%;
        text-align: right;
    }
    .order-good span:first-child{
        text-align: left;
    }
    .order-no{
        font-size: 0.8rem;
        color: #676767;
    }
    .btn_group{
        width: 94%;
        text-align: right;
        margin: 0 3%;
        border-top: 0.02rem solid #d8d8d8;
    }
    .btn{
        width: 5rem;
        height: 2rem;
        background: #fff;
        color: #333;
        border:0.04rem solid #333;
    }
    .btn-1{
        color: #F0463C;
        border-color: #F0463C;
    }
    .order_user{
        font-size: 0.8rem;
        text-align: left;
        margin-left: 0.3rem;
    }
    .earn{
        font-size: 1rem;
        font-weight: bolder;
        margin-bottom: 0.5rem;
    }
    .earn span{
        color: #C20C0C
    }
    .mint-cell-wrapper{
        font-size: 1rem;
    }
    .remember_content{
        font-size: 0.95rem;
        line-height: 3rem;
        border-bottom: 1px solid #bcbcbc;
    }
</style>